$dir =$ARGV[0];
chomp($dir);
$files=`ls $dir`;
@files=split("\n",$files);
$totaltime=0;
$numjobs=0;
for($i=0;$i<@files;$i++)
{
	#print $files[$i]."\n";
	if($files[$i] =~ m/ArrayJob_impute.csh.o\d+.\d+/)
	{
		$numjobs++;
		#print $files[$i]."\n";
		$head= `head -1 $dir/$files[$i]`;
		chomp($head);
		@head = split(" |:",$head);
		$tail= `tail -1 $dir/$files[$i]`;
		chomp($tail);
		@tail= split(" |:",$tail);
		#print $files[$i]."\t".$head."\t".$tail."\n";
		#print "$files[$i]  $head[2] $head[3] $head[4] $head[5]\n";
		
		$head = $head[2]*24*60*60+$head[3]*60*60+$head[4]*60+$head[5];
		$tail = $tail[2]*24*60*60+$tail[3]*60*60+$tail[4]*60+$tail[5];
		$time=($tail-$head)/(60);
		print "$files[$i]\t$time\n";
		$totaltime=$totaltime+$time;
	}
}
print "Total number of jobs : $numjobs Total time: $totaltime\n";
